// vite.config.ts
import { ConfigEnv, UserConfigExport } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import { resolve } from 'path'
import { viteMockServe } from 'vite-plugin-mock'

// 引入Unocss
import Unocss from 'unocss/vite'

// https://vitejs.dev/config/
export default ({ command }: ConfigEnv): UserConfigExport => {
    return {
        plugins: [
            vue(),
            AutoImport({
                imports: [
                    'vue',
                    {
                        'naive-ui': [
                            'useDialog',
                            'useMessage',
                            'useNotification',
                            'useLoadingBar'
                        ]
                    }
                ]
            }),
            Components({
                resolvers: [NaiveUiResolver()]
            }),
            viteMockServe({
                mockPath: 'mock',
                enable: command === 'serve' //command === 'serve' // 生产模式下开启
            }),
            Unocss()
        ],
        resolve: {
            alias: {
                '@': resolve(__dirname, 'src')
            }
        }
    }
}
